package ca.uwo.android.rss.events;

import java.text.SimpleDateFormat;
import java.util.Date;

import android.util.Log;

public class RssEvent {
    
	public int id; // database id
	public int feed_id;
    public String link;
    public String title;
    public String description;
    public String date;
    public Date dateObj;
	
    public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public int getFeed_Id() {
		return feed_id;
	}
	public void setFeed_id(int feed_id) {
		this.feed_id = feed_id;
	}
	public String getLink() {
		return link;
	}
	public void setLink(String link) {
		this.link = link;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	public String getDate() {
		return date;
	}
	public Date getDateObject(){
		return dateObj;
		
	}
	
	public void setDate(String date) {
		
		SimpleDateFormat sdf = null;
		SimpleDateFormat eventFormat = new SimpleDateFormat("MMMM-dd-yy");
		
		if (date.matches("\\d\\d\\d\\d\\x2D\\d{1,2}?\\x2D\\d{1,2}?")) {
			//Log.i("DATE: ", "date matches regex");
			sdf = new SimpleDateFormat("yyyy-MM-dd");
						
		} else { // ('-')/ alumni dates?
			sdf = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
		//	this.date = date.substring(0, date.length() - 6);
		}
		
		dateObj = null;
		try{
			dateObj = sdf.parse(date);
			date = eventFormat.format(dateObj);
		}catch(java.text.ParseException e){
			//Log.e("RssItem", "Error parsing date " + date, e);
			e.printStackTrace();
		}
		
		Log.d("RssItem", "Setting date to " + eventFormat.format(dateObj));
		Log.d("RssItem", "NULL TEST: " + (dateObj == null) );
		
		this.date = date; 
		
	}

} 